<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>给你的，就不会再给别人！！</title>
	<link rel="shortcut icon" href="https://static.hdslb.com/images/favicon.ico">
	<script src="http://libs.baidu.com/jquery/1.11.1/jquery.js"></script>
	<link rel="stylesheet" href="css/demo03.css">
	<link rel="stylesheet" href="css/demo04.css">
	<link rel="stylesheet" href="css/demo05.css">
</head>
<body>
	<div class="top">
		<div class="top-banner">
			<img src="https://s1.hdslb.com/bfs/static/passport/static/img/rl_top.35edfde.png" alt="">
		</div>	
	</div>
	<div class="WB_miniblog">
	<div class="content">
		<div class="left">
			<div id="btn1">首页</div>
			<div id="btn">我的</div>
			<div id="btn2">注销登录</div>
		</div>
		<div class="right">
			<div class="out">
				<div class="head">
					<div class="shadow">
						<img src="http://t9.baidu.com/it/u=2955153989,3173743927&fm=191&app=48&size=h300&n=0&g=4n&f=JPEG?sec=1853310920&t=153aa4fa13a27372f4d76b56eafa22b7"  alt="">
						<p id="name4"></p>
						<div><span>已关注</span><span>私信</span></div>	
					</div>



					
				</div>
				<div class="abc"></div>
				
			</div>
			
		</div>
		<button id="next" style="position: fixed;bottom: 0px;right: 0px;">下一页</button>
	</div>
	<script>
		$("#btn").click(function() {
			location.href = "demo04.html";

		})
		$("#btn1").click(function() {
			location.href = "demo03.html";
		})
		function guolu(n) {
			if (n >= 10) {
				return n ;
			}else {
				return "0" + n;
				}
		}

    	var siteurl = sessionStorage.token;
		var url  = "http://39.105.222.9:8095/blog/query_self_blog/";
		var pose = {"token":siteurl};
		var page = 1;
		var obj1;
		var obj = 10;
		function reload () {
			$.get(url,pose,function(data) {
			if (data.result == 1) {
				obj1 = data.datas;
				var star = 10 *(page - 1 );
				var end = star + obj;
				obj = obj1.slice(star,end);
				for (var i =0;i< obj.length; i++) {
					var qDiv = $("<div class = 'q' id='"+obj[i].id+"''></div>");
					$(".abc").append(qDiv);
					var q1Div = $("<div class = 'q1'></div>");
					q1Div.html("删除");
					qDiv.append(q1Div);
					var wDiv = $("<div class='w'></div>")
					qDiv.append(wDiv);
					var img1 = $("<img src='"+obj[i].portrait+"'>");
					wDiv.append(img1);
					var eDiv = $("<div class='e'></div>");
					wDiv.append(eDiv);
					var rDiv = $("<div class='r'></div>");
					rDiv.html(obj[i].username)
					eDiv.append(rDiv);
					var span1 = $("<span class='t'></span>");
					var myDate = new Date;
			 		var mon = myDate.getMonth() + 1;
			 		var date = myDate.getDate();
					span1.html(mon+"月"+date+ "日");
					eDiv.append(span1);
					var span2 = $("<span class='y'></span>");
					var h1 = myDate.getHours();
					var min1 = myDate.getMinutes();
					span2.html(guolu(h1)+":"+guolu(min1));
					eDiv.append(span2);
					var iDiv = $("<div class='i'></div>");
					iDiv.html(obj[i].content);
					eDiv.append(iDiv);
					var q2Div = $("<div class='q2'></div>");
					qDiv.append(q2Div);
					var span3 = $("<span></span>")
					span3.html("收藏");
					q2Div.append(span3);
					var span4 = $("<span></span>")
					span4.html("转发");
					q2Div.append(span4);
					var span5 = $("<span></span>")
					span5.html("评论");
					q2Div.append(span5);
					var span6 = $("<span></span>")
					span6.html("点赞");
					q2Div.append(span6);
					$("#name4").html(obj[i].username);
				}
				haha();
			}
			
		});
		}
		$("#btn2").click(function(){
    		var siteurl = sessionStorage.token;
			var url ="http://39.105.222.9:8095/blog/logout_user/";
			var  pase  =  {"token":siteurl};
			$.post(url,pase,function(data) {
				if (data.result == 1) {
					sessionStorage.removeItem("token");

				}else {
					alert(data.message);
				}
				// body... 
			})
			
		})
		function haha(){
			$(".q1").click(function(e) {
				var a = $(e.target);
				var b = a.parent()[0].id;

				console.log(b)
				var pose = {"id":b,"token":sessionStorage.token};
				var url = "http://39.105.222.9:8095/blog/del_blog/";
				$.post(url,pose,function (data) {
				if (data.result == 1) {
					$(e.target).parent().remove();
				}else {
					alert(data.message);
				}
			})

				// body... 
			})

		}
		$("#next").click(function() {
			if (Math.floor(obj1.length / 10) > page) {
				page+=1;
		 	$(".abc").html("");
		 	reload(page);
			}else if (Math.floor(obj1.length / 10) == page ) {
				obj = obj1.length % 10;
				page+=1;
				$(".abc").html("");
		 	reload(page);
			}else {
				page = 1;
				obj = 10;
				$(".abc").html("");
				reload(page);
				
			}
		})
		reload(1);

	</script>
</body>
</html>